package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/4/11 9:13
 * Version:1.0-SNAPSHOT
 * Description:
 */
@WebServlet("/method")
public class MethodServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取应用名
        String contextPath = request.getContextPath();
        System.out.println("当前应用名:"+contextPath);

        // 获取当前的访问命令
        // 在非通配符配置的情况下,即为当前的url-pattern
        String path = request.getServletPath();
        System.out.println("当前的访问命令:"+path);

        // 获取请求的uri地址
        // 端口号后面的地址
        // 相当于应用名+访问命令
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri);

        // 获取当前请求完整的url地址
        StringBuffer url = request.getRequestURL();
        System.out.println("url:"+url);

        // 获取访问者的ip地址
        String ip = request.getRemoteAddr();
        System.out.println("访问者ip:"+ip);

    }

}
